var open_id=request("open_id");

//获取验证码
var countdown = 60;
function sendvcode(val) {
    if (countdown == 0) {
    	val.removeAttr("disabled");
        val.val("获取验证码");
        countdown = 60;
        val.css({
        	"color":"#43abeb",
        	"border-color":"#43abeb"
        })
    } else {
    	val.attr("disabled","disabled");
    	val.val("重新获取("+countdown+")");
    	val.css({
        	"color":"#b5b5b5",
        	"border-color":"#b5b5b5"
        })
        countdown--;
        setTimeout(function () {
            sendvcode(val)
        }, 1000)
    }
}
function sendcode(val){
    var m = $(".tel").val().trim();
    if(/^1[3|4|5|7|8]\d{9}$/.test(m)){
    	$.ajax({
            type:"POST",
            timeout:5000,
            url: DATA_URL+"sendmsg",
            data: "phone="+m,
            success: function (data) {
                if(data.code=="0"){
                	//验证码发送成功
                    sendvcode(val);
                }
                else{
                	$(".pop_info").fadeIn(300);
					$(".pop_info .message p").html(data.msg);
                }     
            },
            error:function(){
				$("#prompt").text("您的网络不给力哦~");
		        $(".prompt").fadeIn(300,function(){
		            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
		        })
			}
        });
    }
     else{
    	$("#prompt").text("请输入正确手机号~");
        $(".prompt").fadeIn(300,function(){
            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
        })
    }
}
$(".get_code_btn").click(function(){
	sendcode($(this));
})

$("#sign_up").click(function(){
	if($(".tel").val().trim()==""){
		$("#prompt").text("请输入手机号");
        $(".prompt").fadeIn(300,function(){
            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
        })
        return false;
	}
	if(!(/^1[3|4|5|7|8]\d{9}$/.test($(".tel").val().trim()))){
		$("#prompt").text("请输入正确手机号");
        $(".prompt").fadeIn(300,function(){
            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
        })
		return false;
	}
	if($(".code").val().trim()==""){
		$("#prompt").text("请输入验证码");
        $(".prompt").fadeIn(300,function(){
            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
        })
        return false;
	}
	$.ajax({
	    url: DATA_URL+"wxbind",
	    data: "open_id="+open_id+"&phone="+$(".tel").val().trim()+"&id_code="+$(".code").val().trim(),
	    type: "post",
	    dataType: 'json',
	    timeout: 5000,
	    success:function (data) {
	    	if(data.code=="0"){
	    		location.href="binding_success.html"
	    	}
			else{
				$("#prompt").text(data.msg);
	            $(".prompt").fadeIn(300,function(){
	                setTimeout(function(){$(".prompt").fadeOut(300)},3000)
	            })
			}
	    },
	    error:function () {
	    	$("#prompt").text("您的网络不给力哦~");
	        $(".prompt").fadeIn(300,function(){
	            setTimeout(function(){$(".prompt").fadeOut(300)},3000)
	        })
	    }
	});
	
})
$(".download").click(function(){
	down_load()
})
function down_load(){
	//下载链接
	//ios
	if(navigator.userAgent.indexOf("iPhone")!=-1||navigator.userAgent.indexOf("iPad")!=-1||navigator.userAgent.indexOf("iPod")!=-1){
    	if(navigator.userAgent.indexOf("MicroMessenger")!=-1){
    		//如果在微信打开
    		location.href="http://sj.qq.com/myapp/"
    	}
    	else{
    		//其它方式打开
    		location.href="https://itunes.apple.com/cn/app/%E5%90%AF%E7%A8%8B%E8%80%83%E9%A9%BE%E7%85%A7/id1279692444"
    	}
    }
	//安卓
    else{
    	if(navigator.userAgent.indexOf("MicroMessenger")!=-1){
    		//如果在微信打开
    		location.href="http://sj.qq.com/myapp/"
    	}
    	else{
    		//其它方式打开
    		location.href="http://app.qcjkjg.com/download"
    	}
    }
}
